<?php
namespace app\Components;

use yii\base\Behavior;
use yii\web\Controller;
//自定义一个行为
class HelloBehavior extends Behavior
{
    public $prop1;

    private $_prop2;
    private $_prop3;
    private $_prop4;

    public function events()
    {
        return [
            Controller::EVENT_BEFORE_ACTION => 'getProp2',
            Controller::EVENT_AFTER_ACTION => 'foo'
        ];
    }
    
    public function getProp2()
    {
//         return $this->_prop2;
            echo "22222222222222:Behavior";
    }

    public function setProp3($value)
    {
        $this->_prop3 = $value;
    }

    public function foo()
    {
        // ...

    }

    protected function bar()
    {
        // ...
    }
}